<script type="text/javascript">
$(function(){
	var pg = App.soagov.faceEdit.ui,pp = pg.params;
	var frm = {
		code: pg.seek('code'),
		name: pg.seek('name'),
		face: pg.seek('face'),
		entry: pg.seek('entry'),
		ver: pg.seek('ver'),
		memo: pg.seek('memo')
	}
	function getValues(){
		return {
			id: pg.params.id,
 			parent: pg.params.parent,
 			projId: pg.params.projId,
			code: frm.code.val(),
			name: frm.name.val(),
			face: frm.face.val(),
			entry: frm.entry.val(),
			ver:frm.ver.val(),
			memo: frm.memo.val()
		};
	}
	
	function setValues(o, pom){
		pg.seek('title').html(o.id? '编辑接口':'添加接口');
		frm.code.val(o.code);
		frm.name.val(o.name);
		frm.face.val(o.face);
		frm.entry.val(o.entry);
		frm.ver.val(o.ver);
		frm.memo.val(o.memo);
	}
	function validate(p){
		var msg=pg.seek('msg');
		msg.html('');
		var x = App.validate, v = App.soagov.validation, va = App.base.validation;
		return !x(v.face.code, p.code, msg, '编号') &&
			   !x(v.face.name, p.name, msg, '名称') &&
			   !x(v.face.face, p.face, msg, '接口') &&
			   !x(v.face.entry, p.entry, msg, '入口方法名') &&
			   !x(va.face.ver, p.ver, msg, '版本号') ;
	}
	$("input").blur(function(){
		var pms = getValues();
 		if(!validate(pms))
 			return;
	});
	pg.seek('ok').click(function(){
		var pms = getValues();
 		if(!validate(pms))
 			return;
		$.post(App.ctx + '/face/save.do', pms, function(rs){
			var ro = mac.eval(rs);
			if (ro.success) {
				pg.callback(ro.data);//更新树	
				if(pg.close){
					pg.close();
				}else{
					//pg.callback(null, pg.params.id || pg.params.parent);
				}
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return false;
	});
	setValues(pg.params || {});
	
	pg.seek('close').click(function(){
		var p = pg.params;
		if (pg.close) {
			pg.close();
		}else{
			pg.callback(null, p.id || p.parent);
		}
	});

	if (pg.params.id) {
		/*  frm.code.attr('readonly', true); */
		var w = mac.wait('Loading');
		$.get(App.ctx + '/face/get.do', {
			id : pg.params.id
		}, function(rs) {
			var ro = mac.eval(rs);
			if (ro.success) {
				setValues(ro.data);
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
			w.close();
		}); 
	} else {
		setValues(pg.params, '');
	};
	
});
</script>
<div class="title" name="title">编辑接口</div>
<div class="form code">
	<div class="item">
		<span class="label">编号：</span> <input type="text" name="code"
			placeholder="请填入接口的英文名字" /> <span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">名称：</span> <input type="text" name="name"
			placeholder="请填入接口的中文名字" /> <span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">接口：</span> <input type="text" name="face"
			placeholder="请填入接口类名" /> <span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">入口方法：</span> <input type="text" name="entry"
			placeholder="请填入接口的入口方法" /> <span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">版本号：</span> <input type="text" name="ver"
			placeholder="请填入接口的版本号" /> <span class="msg">*</span>
		<div class="clear"></div>

	</div>
	<div class="item">
		<span class="label">备注：</span>
		<textarea name="memo" placeholder="请填入接口的备注"></textarea>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">&nbsp;</span>
		<div name="msg" class="msg" style="text-align: left;"></div>
		<div class="clear"></div>
	</div>
	<div class="bottom">
		<button name="ok" class="addBtn">确定</button>
		&nbsp;&nbsp;
		<button name="close" class="addBtn">取消</button>
	</div>
</div>